// JavaScript Document
//支持Enter键登录
		document.onkeydown = function(e){
			if($(".bac").length==0)
			{
				if(!e) e = window.event;
				if((e.keyCode || e.which) == 13){
					var obtnLogin=document.getElementById("submit_btn")
					obtnLogin.focus();
				}
			}
		}

		$(function () {
		    var loginName = $("#loginName").val();
		    var password = $("#password").val();
			//提交表单
			$('#submit_btn').click(function(){
				//show_loading();
				if($('#username').val() == ''){
				    $(".message").html("<label for='j_password' class='messageLable'>用户名不能为空！</label>");
					$('#username').focus();
				}else if($('#password').val() == ''){
				    $(".message").html("<label for='j_password' class='messageLable'>密码不能为空！</label>");
					$('#password').focus();
				}else{
				    //ajax提交表单，#login_form为表单的ID。 如：

				    $.post("/Admin/testLogin", { loginName: $('#loginName').val(), password: $('#password').val() }, function (data) {
				        if (data == 1) {
				            setCookie('username', $('#loginName').val(), 180);
				            setCookie('psw', $('#password').val(), 180);
				            window.location = "/Admin/Index";
				        } else if (data == 0) {
				           $(".message").html("<label for='j_password' class='messageLable'>用户名或密码错误！</label>");
				        } else if (data == 2){
				            $(".message").html("<label for='j_password' class='messageLable'>用户名被禁用！</label>！");
				        } else if (data == 3){
				            $(".message").html("<label for='j_password' class='messageLable'>登陆异常！</label>！");
				        }
				    });
				}
			});
    	});
		function reset() {
		    $('#loginName').val("");
		    $('#password').val("");
		}
		function getCookie(c_name) {
		    if (document.cookie.length > 0) {
		        c_start = document.cookie.indexOf(c_name + "=")
		        if (c_start != -1) {
		            c_start = c_start + c_name.length + 1
		            c_end = document.cookie.indexOf(";", c_start)
		            if (c_end == -1) c_end = document.cookie.length
		            return unescape(document.cookie.substring(c_start, c_end))
		        }
		    }
		    return ""
		}

		function setCookie(c_name, value, expiredays) {
		    var exdate = new Date()
		    exdate.setDate(exdate.getDate() + expiredays)
		    document.cookie = c_name + "=" + escape(value) +
            ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
		}
		